package com.tarena.lbs.business.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.business.dao.mapper.BusinessMapper;
import com.tarena.lbs.business.dao.repository.BusinessRepository;
import com.tarena.lbs.business.dao.repository.StoreRepository;
import com.tarena.lbs.business.pojo.po.BusinessPO;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class BusinessRepositoryImpl implements BusinessRepository {
    @Autowired
    private BusinessMapper businessMapper;

    @Autowired
    StoreRepository storeRepository;

    @Override
    public BusinessPO findByName(String businessName) {
//        LambdaQueryWrapper<BusinessPO> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(BusinessPO::getBusinessName, businessName);
        return businessMapper.findByName(businessName);
    }


    @Override
    public Long countByBusinessName(String businessName) {
        LambdaQueryWrapper<BusinessPO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BusinessPO::getBusinessName, businessName);
        if (businessName == null) {
            return 0L;
        }
        return businessMapper.countByBusinessName(businessName);
    }

    @Override
    public void insert(BusinessPO businessPO) {
        businessMapper.insertByBusinessPO(businessPO);

    }

    @Override
    public void deleteById(Integer businessId) {
        businessMapper.deleteById(businessId);
    }

    @Override
    public BusinessPO findById(Integer id) {
        LambdaQueryWrapper<BusinessPO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BusinessPO::getId, id);
        return businessMapper.findById(id);
    }

    @Override
    public BusinessPO busiStoreDetail(Integer businessId) {
        return businessMapper.busiStoreDetail(businessId);
    }

    @Override
    public PageInfo<BusinessPO> pageList(BusinessQuery query) {
        LambdaQueryWrapper<BusinessPO> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(query.getBusinessName() != null, BusinessPO::getBusinessName, query.getBusinessName());
        return new PageInfo<>(businessMapper.SelectListByQuery(query));
    }
}


